let href = location.href;
function getUrlParams(url) {
       let reg = /^[^\s]+\?([^&\s\d]+=[^\s]+)*/
       let match = reg.exec(url)
       match = match[1]
       if (!match) {
           console.warn("没有匹配到相应的query参数")
           return null
       }
       let queryString = decodeURI(match);
       let queryArr = queryString.split("&");
       let queryParamsObj = {}
       queryArr.forEach(item => {
           let itemArr = item.split("=")
           queryParamsObj[itemArr[0]] = itemArr[1]
       })
       return queryParamsObj
   }
let qr = getUrlParams(href)
let { categoryId } = qr;
let {title} = qr
        let html = ''
        html += 
             `
             <li><a href="../index.html">首页></a></li>
             <li><a href="./search.html">全部分类></a></li>
             <li><a href="#">${title}</a></li>
             <li><a href="#">筛选</a></li>
            
             `
        $('.nav').html(html);

 $.ajax({
        type: "get",
        url: `http://chst.vip:1234/api/getproductlist?categoryid=${categoryId}&pageid=1`
    }).then((res) => {
        var arr = res.result;
        let html1 = ''
        arr.forEach(item =>{
             html1 += 
             `
             <li categoryid=${item.categoryId} productListId=${item.productListId} productName=${item.productName}>
                <div class="imge">${item.productImg}</div>
                <div class="infoR">
                    <div class="title">
                        <h4>${item.productName}</h4>
                        <div class="price">${item.productPrice}</div>
                    </div>
                    <div class="other">
                        <span class="price2">${item.productQuote}</span>
                        <i class="iconfont">${item.productCom}</i>
                    </div>
                </div>
            </li>
             `
        })
        $('.info').html(html1)
        $(".info>li").click(function() {
                let categoryid = $(this).attr("categoryid")
                let productListId = $(this).attr("productListId")
                let productName = $(this).attr("productName")
                location.href = `./productList.html?categoryid=${categoryid}&productListId=${productListId}&title=${title}&productName=${productName}`
            })

})